<template>
  <div class="setting-body">
    <el-form ref="form" :model="form" size="small" label-width="120px">
      <div class="custom-tips">
        基础设置
      </div>
      <el-row :gutter="20" style="margin-top: 10px">
        <el-col :span="24">
          <el-form-item label="类型" prop="type" :rules="[{ required: true, message: '请选择类型', trigger: 'change' }]">
            <el-select v-model="form.type" clearable placeholder="请选择类型">
              <el-option
                v-for="obj in openType"
                :key="'entity-'+obj.id"
                :label="obj.label"
                :value="obj.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="是否公众号" prop="isLoginOutType" :rules="[{ required: true, message: '是否公众号', trigger: 'change' }]">
            <el-radio-group v-model="form.isLoginOutType">
              <el-radio
                v-for="item in status"
                :key="item.id"
                :label="item.value"
              >{{ item.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="custom-button">
      <el-button type="text" @click="close">取消</el-button>
      <el-button :loading="loading" type="primary" @click="save('form')">确认</el-button>
    </div>
  </div>
</template>
<script>
import { updateObject } from '@/api/portal/manager/columnTemp';
export default {
  name: 'Portal4PcDividerV1',
  props: {
    data: {
      type: Object,
      default: function() {
        return {};
      }
    }
  },
  data() {
    return {
      loading: false,
      status: [
        { id: 0, value: false, label: '否' },
        { id: 1, value: true, label: '是' }
      ],
      openType: [
        { id: 1, value: 1, label: '注销按钮' }
      ],
      form: {
        title: '',
        content: '',
        type: 1,
        isLoginOutType: false,
        titleFontSize: 16,
        contentFontSize: 12
      }
    };
  },
  watch: {
    data: {
      handler(newName, oldName) {
        if (undefined !== newName) {
          if (undefined !== newName.pzx && newName.pzx !== '' && newName.pzx !== null) {
            this.form = JSON.parse(newName.pzx);
          }
        }
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  },
  methods: {
    save() {
      this.loading = true;
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.data.pzx = JSON.stringify(this.form);
          updateObject(this.data).then(res => {
            this.close();
          }).catch(() => {
            this.loading = false;
          });
        } else {
          this.loading = false;
        }
      });
    },
    close() {
      this.loading = false;
      Object.assign(this.$data.form, this.$options.data.call(this).form);
      this.dialogFormVisible = false;
      this.$emit('fetch-data');
    }
  }
};
</script>
<style scoped>
.setting-body {
  width: 100%;
}
.custom-tips {
  width: 100%;
  min-height: 40px;
  line-height: 40px;
  text-align: left;
  padding: 8px 16px;
  background-color: #ecf8ff;
  border-radius: 4px;
  border-left: 5px solid #50bfff;
}

.custom-button {
  width: 100%;
  height: 40px;
  line-height: 40px;
  text-align: right;
}
</style>
